﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using PHMEE.Admin.Controllers;
using PHMEE.ToolKits;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;

namespace PHMEE.Admin.HttpApi.Controllers.BaseInfo.Mainenances
{

    /// <summary>
    /// 维保建议管理🚢🌞🌛✨
    /// </summary>
    [Route("phmeeadmin/api/mainenanceAdvice")]
    public class MainenanceAdviceController : PHMEEAdminController
    {
        private readonly IMainenanceAdviceAppService mainenanceAdviceAppService;

        /// <summary>
        /// 构造器注入
        /// </summary>
        /// <param name="mainenanceAdviceAppService"></param>
        public MainenanceAdviceController(IMainenanceAdviceAppService mainenanceAdviceAppService)
        {
            this.mainenanceAdviceAppService = mainenanceAdviceAppService;
        }

        /// <summary>
        /// 创建维保建议
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("CreateMainenanceAdvice")]
        public async Task<Guid> CreateMainenanceAdvice(MainenanceAdviceCreateDto input)
        {
            return await mainenanceAdviceAppService.CreateMainenanceAdviceAsync(input);
        }

        /// <summary>
        /// 更新维保建议
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPut]
        [Route("UpdateMainenanceAdvice")]
        public async Task UpdateMainenanceAdvice(MainenanceAdviceUpdateDto input)
        {
            await mainenanceAdviceAppService.UpdateMainenanceAdviceAsync(input);
        }

        /// <summary>
        /// 维保建议详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("GetMainenanceAdviceById")]
        public async Task<MainenanceAdviceDto> GetMainenanceAdviceById(Guid id)
        {
            return await mainenanceAdviceAppService.GetMainenanceAdviceByIdAsync(id);
        }

        /// <summary>
        /// 删除维保建议
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete]
        [Route("DeleteMainenanceAdvice")]
        public async Task DeleteMainenanceAdvice(Guid id)
        {
            await mainenanceAdviceAppService.DeleteMainenanceAdviceAsync(id);
        }

        /// <summary>
        /// 维保建议分页集合
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("GetPagedMainenanceAdvices")]
        public async Task<PagedResultDto<MainenanceAdviceDto>> GetPagedMainenanceAdvices(MainenanceAdviceListDto input)
        {
            return await mainenanceAdviceAppService.GetPagedMainenanceAdvicesAsync(input);
        }


        /// <summary>
        /// 下载维保建议Excel模板
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("GenerateTemplate")]
        public async Task<FileContentResult> GenerateTemplate()
        {
            byte[] bytes = await mainenanceAdviceAppService.GenerateTemplateAsync();
            return File(bytes, PhmeeConst.Mimexlsx, "轴承库模板.xlsx");
        }

        /// <summary>
        /// 批量导入维保建议Excel
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("ImportTemplate")]
        public async Task<OperationResult> ImportTemplate(IFormFile file)
        {
            return await mainenanceAdviceAppService.ImportTemplateAsync(await file.GetAllBytesAsync(), file.FileName);

        }

    }
}
